package com.example.calender.utils

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import com.example.calender.R

class DialogOneEditUtils {


    companion object {
        @JvmStatic
        fun getInitialize(content:Context,dialogClick:DialogClick, text:String){
            var bottomDialog = Dialog(content, R.style.BottomDialog)
            var layout = LayoutInflater.from(content).inflate(R.layout.dialog_layout,null)
            bottomDialog.setContentView(layout)
            var params = layout.layoutParams as ViewGroup.MarginLayoutParams
            params.width = content.resources.displayMetrics.widthPixels -
                    DensityUtil.dip2px(content, 50f)
            params.bottomMargin = 0
            layout.layoutParams = params
            bottomDialog.window!!.setGravity(Gravity.CENTER)
            bottomDialog.window!!.setWindowAnimations(R.style.BottomDialog_Animation)
            bottomDialog.setCanceledOnTouchOutside(false)
            bottomDialog.show()
            layout.findViewById<TextView>(R.id.tv_text).text = text
            layout.findViewById<TextView>(R.id.tv_determine)
                    .setOnClickListener {
                        bottomDialog.hide()
                        dialogClick.determineClick()
                    }
            layout.findViewById<TextView>(R.id.tv_cancel)
                    .setOnClickListener {
                        bottomDialog.hide()
                        dialogClick.cancelClick()
                    }
        }
    }

    interface DialogClick{

        fun determineClick()

        fun cancelClick()
    }
}